package Object类.equals方法.test01;

import java.util.Objects;

public class MyTime {
    int year;
    int month;
    int day;

    public MyTime() {
    }

    public MyTime(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    /*public boolean equals(Object obj) {
         int year1 = this.year;
         int month1 = this.month;
         int day1 = this.day;
         if(obj instanceof Object){
             MyTime t = (MyTime) obj;
             int year2 = t.year;
             int month2 = t.month;
             int day2 = t.day;
             if(year1 == year2 && month1 == month2 && day1 == day2){
                 return true;
             }
         }
         return false;
    }*/

    /*public boolean equals(Object obj) {
        if(obj == null){
            return false;
        }
        if(!(obj instanceof MyTime)){
            return false;
        }
        if(this == obj){
            return true;
        }
        MyTime t = (MyTime) obj;
        return (year == t.year && month == t.month && day == t.day);

    }*/
    /*public boolean equals(Object obj) {
        if(obj == null || !(obj instanceof MyTime)){
            return false;
        }
        if(this == obj){
            return true;
        }
        MyTime t = (MyTime) obj;
        return (year == t.year && month == t.month && day == t.day);*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyTime myTime = (MyTime) o;
        return year == myTime.year &&
                month == myTime.month &&
                day == myTime.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }

    @Override
    public String toString() {
        return "MyTime{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}
